# _*_coding:utf-8_*_
"""
ATS constant define file
"""
import os
import pathlib

start_path = os.getcwd()
print("start_path",start_path)
# start_path = str(pathlib.Path.cwd())
# Build flag, if use source code it is False, if build patch,needs to change to True
build = False
if build:
    ats_name = 'server'
    gui_name = 'client'
else:
    ats_name = 'ats'
    gui_name = 'gui'

ats_index = start_path.lower().find(ats_name)
gui_index = start_path.lower().find(gui_name)

init_path = None
if ats_index != -1:
    if build:
        init_path = os.path.dirname(start_path)
        # init_path = pathlib.PurePath.parent(start_path)
    else:
        init_path = os.path.dirname(os.path.dirname(start_path))
        # init_path = pathlib.PurePath.parent(pathlib.PurePath.parent(start_path))
elif gui_index != -1:
    init_path = os.path.dirname(start_path)
init_path = os.path.dirname(start_path)

if init_path is None:
    print("Error: Cannot get valid init_path. Init_path is None!")

ATS_PATH = os.path.join(init_path, ats_name)
PLANS_PATH = os.path.join(init_path, "plans")
DB_PATH = os.path.join(init_path, "ATS\Data")
if not os.path.exists(DB_PATH):
    os.makedirs(DB_PATH)
GUI_PATH = os.path.join(init_path, gui_name)
# print("GUI_PATH", GUI_PATH)
STDF_PATH = os.path.join(GUI_PATH, "StdfModule", "stdf.ini")
# application program path
EXE_PATH = os.path.dirname(os.getcwd())
LOG_PATH = os.path.join(EXE_PATH, 'ATS_Log')
LOG_FILE_PREFIX = 'ATS_Log'
if gui_index != -1:
    LOG_PATH = os.path.join(GUI_PATH, 'GUI_Log')
    LOG_FILE_PREFIX = 'GUI_Log'
if not os.path.exists(LOG_PATH):
    os.makedirs(LOG_PATH)

# For input test plan files definition
GDF_PATH = os.path.join(PLANS_PATH, 'gdf')
PMF_PATH = os.path.join(PLANS_PATH, 'pmf')
UAP_PATH = os.path.join(PLANS_PATH, 'uap')
TEST_PATH = os.path.join(PLANS_PATH, 'test')

PPF_PATH = os.path.join(PLANS_PATH, 'ppf')
WDF_PATH = os.path.join(PLANS_PATH, 'wdf')
SSPF_PATH = os.path.join(PLANS_PATH, 'sspf')
INI_PATH = os.path.join(PLANS_PATH, 'ini')

# RCF_PATH = os.path.join(init_path, 'config')
RCF_PATH = os.path.join(start_path, 'config')
##Prober configuration related
IGNORE_1st_WAFER_LOAD = False

##EE configuration related
EE_THREAD_NO = 1

# myLog level setting
if build:
    LOG_LEVEL = 4
else:
    LOG_LEVEL = 1

# Field setting, whether it is semiconductor or not
SEMICONDUCTOR_FIELD = 1
FIELD = SEMICONDUCTOR_FIELD

# DB constant
DB_FILE_FOLDER_NAME = "Data"
BASE_DIR = os.path.join(init_path, DB_FILE_FOLDER_NAME)
DB_FILE_NAME = "TestData"
# BASE_DIR = "D:\\projects"
DB_FILE_POST = ".db"
DATA_MODEL_INSTANCE = "DATA_MODEL"
INDEX_LOC_MAP = 'index_locid_map'
SSPF_TESTS_KEY = 'tests'
TEST_TABLE_MAP = 'test_table_map'

MANUAL_RUN_PPF = 'ATS_SingleTestPlan.ppf'
MANUAL_RUN_SSPF = 'ATS_SingleTestPlan.sspf'

INK_POSTFIX = '_porf'
INK_ORI_PPF = "ink_ori_ppf"
INKING_PPF_POSTFIX = "_inking.ppf"
ADD_BIN_SORT = 0
CUSTOMIZE_FOR_LOOP = 0

DB_INSERT_TYPE = "Insert"
DB_UPDATE_TYPE = "Update"
DB_TASK_TYPE = 'DbTaskType'
DB_TASK_VALUE = "DbTaskValue"

CURR_PPF_KEY = "curr_ppf"
OUTPUT_MODELS_KEY = "output_model_dic"
CURR_DB_FILE = "CURR_DB"

# The only flag to make DBServer working to perform transaction submit
ENABLE_DB_SERVER = False
# Force to perform location registration
NEED_REGISTER_LOCATION = True
# 探针台的地址
PROBE_STATION_ADDRESS = "127.0.0.1"
REFRENCE_DATA_PATH = os.path.join(INI_PATH, "reference_data.ini")
REFRENCE_DATA_SECTION = "reference_data"
